CREATE TABLE [dbo].[tb_Caracteristicas]
(
[idCaracteristica] [int] NOT NULL IDENTITY(1, 1),
[Caracteristica] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[TipoCaracteristica] [int] NOT NULL,
[Subtipo] [int] NULL,
[TipoValor] [int] NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[deletetb_Caracteristicas] ON [dbo].[tb_Caracteristicas]
 FOR DELETE AS 
	DELETE tb_ValoresCaracteristicas FROM tb_ValoresCaracteristicas
	 WHERE Caracteristica in (SELECT idCaracteristica FROM deleted)
GO
ALTER TABLE [dbo].[tb_Caracteristicas] ADD CONSTRAINT [PK_tb_Caracteristicas] PRIMARY KEY NONCLUSTERED  ([idCaracteristica]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_Caracteristicas] WITH NOCHECK ADD CONSTRAINT [FK_tb_Caracteristicas_tb_SubTiposCaracteristicas] FOREIGN KEY ([Subtipo]) REFERENCES [dbo].[tb_SubTiposCaracteristicas] ([IdSubtipo])
GO
ALTER TABLE [dbo].[tb_Caracteristicas] WITH NOCHECK ADD CONSTRAINT [FK_tb_Caracteristicas_tb_TiposCaracteristicas] FOREIGN KEY ([TipoCaracteristica]) REFERENCES [dbo].[tb_TiposCaracteristicas] ([idTipoCaracteristicas])
GO
ALTER TABLE [dbo].[tb_Caracteristicas] WITH NOCHECK ADD CONSTRAINT [FK_tb_Caracteristicas_tb_TiposDeValor] FOREIGN KEY ([TipoValor]) REFERENCES [dbo].[tb_TiposDeValor] ([idTipoValor])
GO
